/*
* Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* $Id: ircmodel.h 319 2009-02-22 21:08:23Z vjousse $
*/

#ifndef IRCMODEL_H
#define IRCMODEL_H

#include <QHash>
#include <QStandardItemModel>

class IrcModelItem;
namespace Irc { class Session; }

class IrcModel : public QStandardItemModel
{
    Q_OBJECT

public:
    IrcModel(QObject* parent = 0);
    ~IrcModel();

	/*!
	    Add an item with a session attached to it
	*/
	IrcModelItem* addSession(Irc::Session* session, const QString& name = QString());
    void removeSession(Irc::Session* session);

    void connected(Irc::Session* session);
    void disconnected(Irc::Session* session);
    void nickChanged(Irc::Session* session, const QString& origin, const QString& nick);
    void quit(Irc::Session* session, const QString& origin, const QString& message);
    void joined(Irc::Session* session, const QString& origin, const QString& channel);
    void parted(Irc::Session* session, const QString& origin, const QString& channel, const QString& message, bool me = false);
    void channelModeChanged(Irc::Session* session, const QString& origin, const QString& channel, const QString& mode, const QString& args);
    void userModeChanged(Irc::Session* session, const QString& origin, const QString& mode);
    void topicChanged(Irc::Session* session, const QString& origin, const QString& channel, const QString& topic);
    void kicked(Irc::Session* session, const QString& origin, const QString& channel, const QString& nick, const QString& message);
    void channelMessageReceived(Irc::Session* session, const QString& origin, const QString& channel, const QString& message, bool current = true);
    void privateMessageReceived(Irc::Session* session, const QString& origin, const QString& receiver, const QString& message);
    void noticeReceived(Irc::Session* session, const QString& origin, const QString& receiver, const QString& message);
    void invited(Irc::Session* session, const QString& origin, const QString& nick, const QString& channel);
    void ctcpRequestReceived(Irc::Session* session, const QString& origin, const QString& message);
    void ctcpReplyReceived(Irc::Session* session, const QString& origin, const QString& message);
    void ctcpActionReceived(Irc::Session* session, const QString& origin, const QString& receiver, const QString& message);
    void unknownMessageReceived(Irc::Session* session, const QString& origin, const QStringList& params);
    void numericMessageReceived(Irc::Session* session, const QString& origin, uint event, const QStringList& params);

private:
    IrcModelItem* topLevelItem(Irc::Session* session, const QString& name = QString());

    struct IrcModelData
    {
        mutable QHash<Irc::Session*, IrcModelItem*> topLevelItems;
    } d;
};

#endif // IRCMODEL_H
